package enumdemo;

public enum TestEnum {
    //枚举对象
    RED("红色",3),BLACK("黑色",0),GREEN("绿色",1),YELLOW("黄色",2);

    public String color;
    public int ordinal;

    private TestEnum(String color,int ordinal) {
        this.color = color;
        this.ordinal = ordinal;
    }

    public static void main(String[] args) {
        //遍历输出枚举
        TestEnum[] testEnums = TestEnum.values();
        for (TestEnum testEnum : testEnums) {
            System.out.println(testEnum.ordinal());//.ordinal是获取枚举的索引位置
        }
        System.out.println("===============");

        TestEnum val=TestEnum.valueOf("RED");
        System.out.println(val);//这个val是枚举类型

        System.out.println(BLACK.compareTo(GREEN));//比较的是索引
    }

    public static void main1(String[] args) {
        TestEnum testEnum=RED;
        switch(testEnum){
            case RED:{
                System.out.println("RED");
                break;
            }
            case BLACK:{
                System.out.println("BLACK");
                break;
            }
            case GREEN:{
                System.out.println("GREEN");
                break;
            }
            case YELLOW:{
                System.out.println("YELLOW");
                break;
            }
            default:{
                System.out.println("DEFAULT");
                break;
            }
        }
    }
}
